- [About](#about)
- [Setup](#setup)
  - [Installing Emacs](#installing-emacs)
  - [Installing required Emacs packages](#install-emacs-packages)
  - [Configuring Emacs using Elisp code](#configuring-emacs)
- [Test](#test)
  - [Running geiser](#running-geiser)
  - [Literate programming document](#example-document)
- [Report](#report)



<a id="about"></a>

# About

This section aims to provide the minimal steps required to get literate programming in org-mode working for GNU Guile.


<a id="setup"></a>

# Setup


<a id="installing-emacs"></a>

## Installing Emacs

We will use GNU Guix to create a reproducible environment, in which we will run Emacs, install Emacs packages and configure Emacs using Elisp code.


### Reproducible Emacs using GNU Guix


#### Create manifest.scm

```shell
cat <<EOT > manifest.scm
(specifications->manifest
 '("gnutls"
   "guile"
   "bash"
   "emacs"))
EOT

cat manifest.scm
```


#### Create channels.scm

```shell
guix describe --format='channels' > 'channels.scm'
cat 'channels.scm'
```

(list (channel (name 'guix) (url "<https://git.savannah.gnu.org/git/guix.git>") (branch #f) (commit "a1cb645d83d085382eaf64f4c097642aa47c297a") (introduction (make-channel-introduction "9edb3f66fd807b096b48283debdcddccfea34bad" (openpgp-fingerprint "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA")))))


#### Install packages

```shell
command -V guile
ls -al $(command -V guile)

# compare to guile installed in the environment created via guix shell:

guix time-machine \
     --channels="channels.scm" -- \
     shell \
     --cores=8 \
     --manifest="manifest.scm" -- \
     which guile && ls -al $(which guile)
```


#### Command for running Emacs inside reproducible environment

```shell
guix time-machine \
     --channels="channels.scm" -- \
     shell \
     --cores=8 \
     --pure \
     --container \
     --network \
     --no-cwd \
     --preserve='TERM' \
     --manifest="manifest.scm" -- \
     emacs \
     --no-init-file \
     --no-site-file \
     --no-site-lisp \
     --no-splash \
     --no-x-resources \
     --no-desktop \
     --no-loadup \
     --no-window-system
```

Or with graphical window:

```shell
guix time-machine \
     --channels="channels.scm" -- \
     shell \
     --cores=8 \
     --pure \
     --container \
     --network \
     --no-cwd \
     --share=/tmp/.X11-unix \
     --preserve='DISPLAY' \
     --preserve='TERM' \
     --manifest="manifest.scm" -- \
     emacs \
     --no-init-file \
     --no-site-file \
     --no-site-lisp \
     --no-splash \
     --no-x-resources \
     --no-desktop \
     --no-loadup
```


<a id="install-emacs-packages"></a>

## Installing required Emacs packages


### Add melpa-stable package repository

To install geiser, we need to add the package repository, from which we can pull it.

Run the following elisp code:

```elisp
(require 'package)
;; (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
```


### Install org

`org` is already installed. Not sure how to tell Emacs, that it should instead install `org` from GNU Elpa, so do this manually:

-   `M-x list-pack RET`
-   search for `org` from GNU Elpa
-   install `org`


### Installing geiser-guile

As Elisp code:

```elisp
(package-install 'geiser-guile)
```


<a id="configuring-emacs"></a>

## Configuring Emacs using Elisp code

The following Elisp code needs to be evaluated, to be able to evaluate org source blocks of Scheme code using GNU Guile:

```elisp
;; Tell Emacs to use the command `guile` to evaluate Scheme
;; code.
(setq scheme-program-name "guile")

;; The following enables source blocks of specific
;; programming languages to be executed. By default only
;; elisp is allowed to be executed. First we define an
;; association list of languages to booleans, which enable
;; or disable support for a language.
(setq org-babel-load-languages
      '((scheme . t)))

;; Then we use org-babel-do-load-languages to actually tell
;; org babel, that the languages should be supported.
(org-babel-do-load-languages
 'org-babel-load-languages
 '((scheme . t)))

;; The following defines a procedure, which determins, which
;; source blocks of programming languages can be run without
;; confirmation, depending on the language. The procedure
;; can then be used as org-confirm-babel-evaluate value.
(defun xiaolong/org-confirm-babel-evaluate (lang body)
  (not
   (or (string= lang "scheme"))))

;; Set a procedure predicate for org babel, to determin, which languages can
;; be run without confirmation.
(setq org-confirm-babel-evaluate 'xiaolong/org-confirm-babel-evaluate)
```


<a id="test"></a>

# Test


<a id="running-geiser"></a>

## Running geiser

Run geiser-guile using the following command:

    M-x run-geiser RET

Since only `geiser-guile` is installed, this should start a Geiser Guile REPL.


<a id="example-document"></a>

## Literate programming document

Now we should be all set to try some literate programming in Scheme.

Here is an example document:

```shell
cat example.org
```

1.  Open a new `.org` file.
2.  Paste the `example.org` document into the buffer of the `.org` file.
3.  Place the cursor inside the `usemember` source block.
4.  Input `C-c C-c` to evaluate the source block.


<a id="report"></a>

# Report

The above does not seem to work. The result of the example source block is merely the following:

>     Geiser Interpreter produced no output